#include"processbar.h"
#include<string.h>
#include<unistd.h>
const char* label="|/-\\";
//#define GREEN "\033[0;32;32m"
//#define RED "\033[0;31;32m"
//#define NONE "\033[0;32;32m"
char buf[NUM]={0};
void processbar(int rate)
{                 
    if(rate<0||rate>NUM)
        return ;
    int len=strlen(label);                                
    printf("[%-100s]""[%d%%][%c]\r",buf,rate,label[rate%len]);
    fflush(stdout);
    //rate[0,99]
    buf[rate++]=STYLE;    
    if(rate<NUM) buf[rate]=Boot;
    printf("\n");
}               
void inibar()
{
    memset(buf,'\0',sizeof(buf)+1);
}
//v2

//v1
/*void processbar(int rate)
{
    int cnt=0;
    char buf[NUM]={0};
    while(cnt<=NUM)
    {
        int len=strlen(label);
        printf("[%-100s][%d%%][%c]\r",buf,cnt,label[cnt%len]);
        buf[cnt++]=STYLE;
        if(cnt<NUM)
            buf[cnt]=Boot;
        fflush(stdout);
        usleep(rate);
    }
    printf("\n");
}
*/
